<?php
class Tag {
	public $name;
	public $count;
	private $artists;

	public function Tag($name = "") {
		$this->name = $name;
	}
	
    public function getArtists() {
        
        if(empty($this->name)) {
            throw new Exception("object artist name not set!");
        }
        
        $file = "./cache/artist/tag/".urlencode($this->name).".xml";
        if (@fopen($file, "r")) {
            $xml = file_get_contents($file);
        } else {
            $xml = file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.gettopartists&tag=".urlencode($this->name)."&api_key=519681edb551a3b5177bb67352e16136");
            $fp = @fopen($file, "w");
            if($fp) {
               $result = fwrite($fp, $xml);
            fclose($fp);
            }
        }
        
        $sxml = new SimpleXMLElement($xml);
        $sxml = $sxml->topartists;
        foreach($sxml->artist as $obj) {
            //$artist = new Artist();
            //$artist->name = (string)$artistObj->name;
            //$artist->match = (string)$artistObj->match;
            $this->artists[] = (string)$obj->name;
        }
        
        //Info::dump($this->artists);
        return $this->artists; 
    }

}
?>